package com.seveneight.baijiesteward.views;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.flyco.dialog.widget.popup.base.BaseBubblePopup;
import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.ui.first.activity.ProfitListActivity;
import com.seveneight.baijiesteward.ui.main.activity.LoginActivity;
import com.seveneight.baijiesteward.ui.user.activity.RecordActivity;
import com.seveneight.baijiesteward.utils.Setting;
import com.seveneight.baijiesteward.utils.WindowUtil;

/**
 * Created by user1 on 2018/1/25.
 */

public class RightPopupWindow {

    private Activity activity;
    private View view;
    private SimpleCustomPop simpleCustomPop;

    public RightPopupWindow(Activity activity, View view) {
        this.view = view;
        this.activity = activity;
    }

    public void showDrawingRightWindow() {
        boolean isLogin = Setting.getInstance(activity).isLogin();
        if (!isLogin) {
            WindowUtil.getInstance().startActivity(activity, LoginActivity.class);
            return;
        }
        simpleCustomPop = new SimpleCustomPop(activity);
        simpleCustomPop.anchorView(view)
                .bubbleColor(Color.parseColor("#ffffff"))
                .gravity(Gravity.BOTTOM)
                .triangleWidth(20)
                .triangleHeight(10)
                .showAnim(null)
                .dismissAnim(null)
                .show();
    }

    class SimpleCustomPop extends BaseBubblePopup<SimpleCustomPop> {
        private TextView tv_item_2;
        private TextView tv_item_1;

        public SimpleCustomPop(Context context) {
            super(context);
        }

        @Override
        public View onCreateBubbleView() {
            View view = View.inflate(activity, R.layout.popup_drawing, null);
            tv_item_1 = (TextView) view.findViewById(R.id.tv_item_1);
            tv_item_2 = (TextView) view.findViewById(R.id.tv_item_2);
            return view;
        }

        @Override
        public void setUiBeforShow() {
            super.setUiBeforShow();
            tv_item_1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    WindowUtil.getInstance().startActivity(activity, ProfitListActivity.class, null);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            simpleCustomPop.dismiss();
                        }
                    }, 1000);
                }
            });
            tv_item_2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle1 = new Bundle();
                    bundle1.putString("type", "3");
                    WindowUtil.getInstance().startActivity(activity, RecordActivity.class, bundle1);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            simpleCustomPop.dismiss();
                        }
                    }, 1000);
                }
            });
        }

    }

}
